package lanou.autohome.forum.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import lanou.autohome.R;
import lanou.autohome.forum.beans.ForumHotBean;

/**
 * Created by dllo on 16/8/17.
 * 论坛 -> 热帖
 */
public class ForumHotAdapter extends BaseAdapter{

    Context mcontext;
    ForumHotBean forumHotBean;

    public ForumHotAdapter(Context mcontext) {
        this.mcontext = mcontext;
    }

    public void setForumHotBean(ForumHotBean forumHotBean) {
        this.forumHotBean = forumHotBean;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return forumHotBean != null ? forumHotBean.getResult().getList().size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }


    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ForumViewHolder forumViewHolder = null;
        if(convertView == null){
            convertView = LayoutInflater.from(mcontext).inflate(R.layout.item_forum_hot , null);
            forumViewHolder = new ForumViewHolder(convertView);
            convertView.setTag(forumViewHolder);
        }else {
            forumViewHolder = (ForumViewHolder) convertView.getTag();
        }

        ForumHotBean.ResultBean.ListBean bean = forumHotBean.getResult().getList().get(position);

        forumViewHolder.title.setText(bean.getTitle());
        forumViewHolder.plstdate.setText(bean.getPostdate());
        forumViewHolder.bbsname.setText(bean.getBbsname());
        forumViewHolder.replycounts.setText(bean.getReplycounts() + "回帖");
//        forumViewHolder.ispictipic.setText(String.valueOf(bean.getIspictopic()));
        if(bean.getIspictopic() == 0){
        forumViewHolder.ispictipic.setVisibility(View.INVISIBLE);

        }
        return convertView;
    }

    public class ForumViewHolder{

        TextView title;
        TextView plstdate;
        TextView  bbsname;
        ImageView ispictipic;
        TextView replycounts;
        public ForumViewHolder(View convertView){
            title = (TextView) convertView.findViewById(R.id.title_forum_hot);
            plstdate = (TextView) convertView.findViewById(R.id.postdate_forum_hot);
            bbsname = (TextView) convertView.findViewById(R.id.bbsname_forum_hot);
            ispictipic = (ImageView) convertView.findViewById(R.id.ispictopic_forum_hot);
            replycounts = (TextView) convertView.findViewById(R.id.replycounts_forum_hot);
        }
    }


}

